import os
import 可视化获取文件路径
from pydub import AudioSegment

'''程序功能:压缩mp3文件的体积'''
mp3_paths = 可视化获取文件路径.select_file()
#文件保存位置
zip_save = 可视化获取文件路径.select_mkdir()
# 音频文件路径
path = mp3_paths
path2 = zip_save
path3 = 'ss1xx.mp3'
#音频压缩
def zip_audio(path,path2):
    # 读取音频文件，设置采样率<default=44100>
    song = AudioSegment.from_mp3(path).set_frame_rate(22050)
    path2 = os.path.join(path2,"00001.mp3")
    # 按32k的bitrate导出文件到指定路径
    song.export(path2, format='mp3', bitrate='32k')
    print("压缩完毕")

#音频分割
def xx_audio(path,path3,s,e):
    #开始时间
    start_time = s * 1000
    #结束时间
    end_time = e * 1000
    #选择文件
    sound = AudioSegment.from_mp3(path)
    #进行分割
    word = sound[start_time:end_time]
    #保存
    word.export(path3,format='mp3')

if __name__ == '__main__':
    zip_audio(path,path2)
    #xx_audio(path,path3,34,60)

